"""
Case Type   : 服务端工具
Case Name   : 修改配置文件中参数，同时发送信号量到postgresql.conf时不指定-I或者-D
Create At   : 2021/1/4
Owner       : daiguatutu
Description :
    1.查看krb_caseins_users默认值
    2.修改配置文件中参数，同时发送信号量到postgresql.conf时不指定-I/-D
Expect      :
    1.显示成功
    2.执行失败
History     :
"""

import unittest
from yat.test import Node
from yat.test import macro
from testcase.utils.CommonSH import CommonSH
from testcase.utils.Constant import Constant
from testcase.utils.Logger import Logger

LOG = Logger()


class Tools(unittest.TestCase):
    def setUp(self):
        LOG.info('----Opengauss_Function_Tools_gs_guc_Case0035开始执行----')
        self.dbuser_node = Node('dbuser')
        self.constant = Constant()
        self.commonsh = CommonSH()

    def test_server_tools(self):
        LOG.info('-----步骤1.查看krb_caseins_users默认值-----')
        sql_cmd = self.commonsh.execut_db_sql(f'show krb_caseins_users;')
        LOG.info(sql_cmd)
        self.assertIn('off', sql_cmd)

        LOG.info('-----步骤2.修改配置文件中参数，不指定-N----')
        check_cmd = f'source {macro.DB_ENV_PATH};' \
            f'gs_guc reload -N all -c krb_caseins_users=off;'
        LOG.info(check_cmd)
        msg = self.dbuser_node.sh(check_cmd).result()
        LOG.info(msg)
        self.assertIn(self.constant.GSGUC_SUCCESS_MSG, msg, '设置失败')

    def tearDown(self):
        LOG.info('----------------清理环境-----------------------')
        execute_cmd2 = f'source {macro.DB_ENV_PATH};' \
                       f'gs_guc reload -N all -c "krb_caseins_users";'
        LOG.info(execute_cmd2)
        msg1 = self.dbuser_node.sh(execute_cmd2).result()
        LOG.info(msg1)
        self.assertIn(self.constant.GSGUC_SUCCESS_MSG, msg1, '设置失败')
        LOG.info('----Opengauss_Function_Tools_gs_guc_Case0035执行结束----')
